import Vue from 'vue';
import VueRouter from 'vue-router';
import Layout from '../components/layout'
import userManage from './modules/userManage'
import roleList from './modules/roleList'
import permissionList from './modules/permissionList'
import articleRanking from './modules/articleRanking'
import articleCreate from './modules/articleCreate'

Vue.use(VueRouter);

// 公开路由
export const publicRoutes = [
  {
    path: '/',
    redirect: '/layout'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue'),
  },
  {
    path: '/layout',
    name: 'layout',
    component: Layout,
    redirect: 'profile',
    children: [
      {
        path: '/profile',
        name: 'profile',
        component: () => import('../views/profile/index.vue'),
        meta: {
          title: 'profile',
          icon: 'icon-gerenzhongxin',
        }
      },
      {
        path: '/404',
        name: '404',
        component: () => import('../views/error-page/404.vue')
      },
      {
        path: '/401',
        name: '401',
        component: () => import('../views/error-page/401.vue')
      },
    ]
  },
];



// 自定义私有路由表
export const privateRoutes = [
  userManage,
  roleList,
  permissionList,
  articleRanking,
  articleCreate,
];



// // 私有路由表
// const privateRoutes = [
//   {
//     path: '/user',
//     component: Layout,
//     meta: {
//       title: 'user',
//       icon: 'icon-users'
//     },
//     redirect: '/user/manage',
//     children: [
//       {
//         path: '/user/manage',
//         component: () => import('../views/user-manage/index.vue'),
//         meta: {
//           title: 'userManage',
//           icon: 'icon-yuangongguanli',
//         }
//       },
//       {
//         path: '/user/role',
//         component: () => import('../views/role-list/index.vue'),
//         meta: {
//           title: 'roleList',
//           icon: 'icon-tongxunlu',
//         }
//       },
//       {
//         path: '/user/permission',
//         component: () => import('../views/permission-list/index.vue'),
//         meta: {
//           title: 'permissionList',
//           icon: 'icon-quanxianguanli',
//         }
//       },
//       {
//         path: '/user/info/:id',
//         name: 'userInfo',
//         component: () => import('../views/user-info/index.vue'),
//         meta: {
//           title: 'userInfo',
//         }
//       },
//       {
//         path: '/user/import',
//         name: 'import',
//         component: () => import('../views/import/index.vue'),
//         meta: {
//           title: 'excelImport',
//         }
//       },
//     ]
//   },
//   {
//     path: '/article',
//     component: Layout,
//     meta: {
//       title: 'article',
//       icon: 'icon-describe'
//     },
//     redirect: '/article/ranking',
//     children: [
//       {
//         path: '/article/ranking',
//         component: () => import('../views/article-ranking/index.vue'),
//         meta: {
//           title: 'articleRanking',
//           icon: 'icon-liebiao',
//         }
//       },
//       {
//         path: '/article/create',
//         component: () => import('../views/article-create/index.vue'),
//         meta: {
//           title: 'articleCreate',
//           icon: 'icon-bianjiwenzhang_huaban',
//         }
//       },
//       {
//         path: '/article/:id',
//         component: () => import('../views/article-detail/index.vue'),
//         meta: {
//           title: 'articleDetail',
//         }
//       },
//       {
//         path: '/article/editor/:id',
//         component: () => import('../views/article-create/index.vue'),
//         meta: {
//           title: 'articleEditor',
//         }
//       },
//     ]
//   },
// ];









const router = new VueRouter({
  routes: [...publicRoutes],
});

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function pus(location) {
  return originalPush.call(this.push, location).catch(err => err)
}


export default router;
